home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Caml Light 0.7 / Caml Light 0.7 source / src / lex / grammar.mly < prev    next >
Text File  |  1995-06-01  |  2KB  |  101 lines

  1. /* The grammar for lexer definitions */
  2.  
  3. %{
  4. #open "syntax";;
  5. #open "gram_aux";;
  6. %}
  7.  
  8. %token <string> Tident
  9. %token <char> Tchar
  10. %token <string> Tstring
  11. %token <syntax__location> Taction
  12. %token Trule Tparse Tand Tequal Tend Tor Tunderscore Teof Tlbracket Trbracket
  13. %token Tstar Tmaybe Tplus Tlparen Trparen Tcaret Tdash
  14.  
  15. %left Tor
  16. %left CONCAT
  17. %nonassoc Tmaybe
  18. %left Tstar
  19. %left Tplus
  20.  
  21. %start lexer_definition
  22. %type <syntax__lexer_definition> lexer_definition
  23.  
  24. %%
  25.  
  26. lexer_definition:
  27.     header Trule definition other_definitions Tend
  28.         { Lexdef($1, $3::(rev $4)) }
  29. ;
  30. header:
  31.     Taction
  32.         { $1 }
  33.   |
  34.         { Location(0,0) }
  35. ;
  36. other_definitions:
  37.     other_definitions Tand definition
  38.         { $3::$1 }
  39.   |     
  40.         { [] }
  41. ;
  42. definition:
  43.     Tident Tequal entry
  44.         { ($1,$3) }
  45. ;
  46. entry:
  47.     Tparse case rest_of_entry
  48.         { $2::rev $3 }
  49. ;
  50. rest_of_entry:
  51.     rest_of_entry Tor case
  52.         { $3::$1 }
  53.   |
  54.         { [] }
  55. ;
  56. case:
  57.     regexp Taction
  58.         { ($1,$2) }
  59. ;
  60. regexp:
  61.     Tunderscore
  62.         { Characters all_chars }
  63.   | Teof
  64.         { Characters [`\000`] }
  65.   | Tchar
  66.         { Characters [$1] }
  67.   | Tstring
  68.         { regexp_for_string $1 }
  69.   | Tlbracket char_class Trbracket
  70.         { Characters $2 }
  71.   | regexp Tstar
  72.         { Repetition $1 }
  73.   | regexp Tmaybe
  74.         { Alternative($1, Epsilon) }
  75.   | regexp Tplus
  76.         { Sequence($1, Repetition $1) }
  77.   | regexp Tor regexp
  78.         { Alternative($1,$3) }
  79.   | regexp regexp %prec CONCAT
  80.         { Sequence($1,$2) }
  81.   | Tlparen regexp Trparen
  82.         { $2 }
  83. ;
  84. char_class:
  85.     Tcaret char_class1
  86.         { subtract all_chars $2 }
  87.   | char_class1
  88.         { $1 }
  89. ;
  90. char_class1:
  91.     Tchar Tdash Tchar
  92.         { char_class $1 $3 }
  93.   | Tchar
  94.         { [$1] }
  95.   | char_class1 char_class1 %prec CONCAT
  96.         { $1 @ $2 }
  97. ;
  98.  
  99. %%
  100.  
  101.